﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>编研管理</title>
	<jsp:include page="/zheng-admin-plugins/plugins/inc/head.jsp" flush="true"/>
	<style>
		.bootstrap-table .table>thead>tr>th {
			border-bottom:1px solid #ddd;
		}
	</style>
</head>
<body style="overflow:hidden;">
<div id="main">
	<div id="toolbar">
		<shiro:hasPermission name="upms:stumanages:deleteAnyway">
			<a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除编研</a>
		</shiro:hasPermission>
	</div>
	<table id="table"></table>

	<!-- 查看图片 -->
	<div id="showImg" class="modal fade archivePopUp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:900px;height: 700px;text-align: center;">
			<div class="modal-content" style="height: 100%;">
				<div id="borAttestPdf" style="height:100%;width: 100%">
					<img id="borAttestImg" style="height:100%;width: 100%;display: none" />
				</div>
			</div>
		</div>
	</div>
</div>
<%--<jsp:include page="/zheng-admin-plugins/plugins/inc/footer.jsp" flush="true"/>--%>
<jsp:include page="/inc/footer.jsp" flush="true"/>
<script src="${basePath}/js/date.js"></script>
<script>
var $table = $('#table');
$(function() {
	// bootstrap table初始化
	$table.bootstrapTable({
		url: '${basePath}/manage/studymanage/list',
        striped: true,
//        search: true,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,
        detailView: false,
        detailFormatter: 'detailFormatter',
        pagination: true,
        paginationLoop: false,
        sidePagination: 'server',
        silentSort: false,
        smartDisplay: false,
        escape: true,
        searchOnEnterKey: true,
		idField: 'stuId',
		maintainSelected: true,
		toolbar: '#toolbar',
		columns: [
			{field: 'ck', checkbox: true},
			{field: 'stuId', title: 'id', align: 'center',visible:false },
            {field: 'subject', title: '主题', width:'50%',align: 'center'},
            {field: 'submitter', title: '发布者', align: 'center'},
			{field: 'stuUpdateDate', title: '发布时间', align: 'center',formatter:'timeFormatter'},
			{field: 'stuFileAddress',title : '操作', align: 'center', formatter:'downloadFile'}
		],
        onLoadSuccess:function(data){
            //无数据隐藏分页
            if(data && data.total == 0){
                $('.fixed-table-pagination').hide()
            }
        }
	});
    $table.bootstrapTable('resetView',{height:setHeight()});

});

/**
 * 表格高度自适应
 * @return
 * winTop 浏览器视口高度
 * header 顶部通栏
 * breadcrumb 面包屑
 * mainFooter 底部
 */
function setHeight(){
    var winTop = $(window.top).height(),
        header = window.top.document.querySelector('.main-header').offsetHeight,
        breadcrumb =  window.top.document.querySelector('.breadcrumb').offsetHeight,
        mainFooter = window.top.document.querySelector('.main-footer').offsetHeight;
    return winTop-header-breadcrumb-mainFooter-10;
}
/**
 *	格式化时间(格式YYYY-dd-MM HH:mm:ss)
 */
function timeFormatter(value , row, index) {
	return formatshortDateTime(value);
}
function downloadFile(value,row,index){
	if(value != null && value !="" && value != undefined){
		return '<a  href="javascript:void(0);" onclick="showFile(\''+value+'\');" ><span class="label label-success"> 查看附件</span ></a>';
	}else{
		return '无附件';
	}
}

//查看文件证明图片
function showFile(imgUrl){
    if(imgUrl.indexOf("pdf")!=-1){
        $("#borAttestImg").hide();
        var options={
            pdfOpenParams: {
                pagemode: "thumbs",
                navpanes: '0',
				toolbar: '0', //去掉工具栏,打印,下载等,,,,
                statusbar: '0',
                view: 'FitV'
            }};
        //var url="${basePath} /localpdf/大型网站技术架构_核心原理与案例分析_李智慧.pdf";
        var myPDF = PDFObject.embed(imgUrl, "#borAttestPdf", options);
    }else{
        $("#borAttestImg").show();
        $("#borAttestImg").attr({ src: imgUrl, alt: "查看图片" });
    }
    $("#showImg").modal("show");
}



// 删除
var deleteDialog;
function deleteAction() {
    var rows = $table.bootstrapTable('getSelections');
    if (rows.length == 0) {
        $.confirm({
            title: false,
            content: '请至少选择一条记录！',
            autoClose: 'cancel|3000',
            backgroundDismiss: true,
            buttons: {
                cancel: {
                    text: '取消',
                    btnClass: 'waves-effect waves-button'
                }
            }
        });
    } else {
        deleteDialog = $.confirm({
            type: 'red',
            animationSpeed: 300,
            title: false,
            content: '确认删除该编研资料吗？',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'waves-effect waves-button',
                    action: function () {

                        $.ajax({
                            type: 'get',
                            url: '${basePath}/manage/studymanage/delete?id=' + rows[0].stuId,
                            success: function(result) {
                            	reConfirm(result.message);
                                if (result.code == 1) {
									deleteDialog.close();
									$table.bootstrapTable('refresh');
                                }
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                $.confirm({
                                    theme: 'dark',
                                    animation: 'rotateX',
                                    closeAnimation: 'rotateX',
                                    title: false,
                                    content: textStatus,
                                    buttons: {
                                        confirm: {
                                            text: '确认',
                                            btnClass: 'waves-effect waves-button waves-light'
                                        }
                                    }
                                });
                            }
                        });
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'waves-effect waves-button'
                }
            }
        });
    }
}
function reConfirm(content) {
	$.confirm({
		title: "提示",
		content: content,
		autoClose: 'cancel|3000',
		backgroundDismiss: true,
		buttons: {
			cancel: {
				text: '确定',
				btnClass: 'waves-effect waves-button'
			}
		}
	});
}
</script>
</body>
</html>